<template>
  <div class="app-container">
    <div class="background-color: #fff;">
      <!-- 查询 -->
      <div class="filter-container">
        <el-form :inline="true" class="search-form" label-width="100px">
          <el-row style="display: flex; flex-wrap: wrap">
            <div style="flex: 1">
              <el-form-item label="供货商名称" style="margin: 5px 0">
                <el-select style="width: 100%" clearable v-model="searchForm.supplier_id" filterable placeholder="请输入供货商名称搜索">
                  <el-option v-for="item in options" :key="item.id" :label="item.supplier_name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="结算时间" style="margin: 5px 0">
                <el-date-picker @change="supliertime" v-model="searchFormtime" clearable value-format="yyyy-MM-dd"
                  type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </div>
            <div style="padding: 5px 0">
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="getQuery">查询</el-button>
                <el-button type="primary" icon="el-icon-refresh" @click="resettingWay">重置</el-button>
              </el-form-item>
            </div>
          </el-row>
        </el-form>
      </div>
    </div>
    <el-divider />
    <div class="grouping" style="margin-top: 20px;padding: 0 20px 20px;">
      <div class="marginBottom">
        <el-row :gutter="20" style="display: flex">
          <el-col>
            <el-button type="primary" size="small"
              @click="addGoodsWay()">添加结算</el-button>
          </el-col>
          <el-col :span="8" style="float: right">
            <div class="right-panel el-button-group">
              <el-button icon="el-icon-refresh" size="mini" @click="resettingWay" />
              <el-dropdown trigger="click" :hide-on-click="false">
                <span class="el-dropdown-link">
                  <el-button icon="el-icon-s-operation" size="mini" />
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="fruit in allTableThead" :key="fruit">
                    <el-checkbox v-model="checkboxTableThead" :label="fruit">{{
                      tableTheadOptions[fruit].label
                    }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </el-col>
        </el-row>
      </div>
      <el-row :gutter="20">
        <el-col>
          <el-table v-loading="loading" :data="GoodsLists" :header-cell-style="{
              'background-color': '#f3f8fe',
              color: '#606266',
              height: '50px',
            }" style="width: 100%">
            <el-table-column v-for="fruit in tableThead" :key="fruit" :label="tableTheadOptions[fruit].label"
              align="center">
              <template slot-scope="scope">
                <div v-if="fruit == 'batch_number'">
                  <el-tooltip placement="top-start" :content="scope.row.batch_number + ''">
                    <div class="one_line_hidden" style="color: #1890ff;">
                      {{ scope.row.batch_number ? scope.row.batch_number : "-" }}
                    </div>
                  </el-tooltip>
                </div>
                <div v-else-if="fruit == 'supplier_name'">
                  <el-tooltip placement="top-start" :content="scope.row.supplier_name + ''">
                    <div class="one_line_hidden" style="color: #1890ff;">
                      {{ scope.row.supplier_name ? scope.row.supplier_name : "-" }}
                    </div>
                  </el-tooltip>
                </div>
                <div v-else-if="fruit == 'start_time'">
                  <el-tooltip placement="top-start" :content="scope.row.start_time + '~'+ scope.row.end_time +''">
                    <div class="one_line_hidden">
                      {{scope.row.start_time + '~' + scope.row.end_time}}
                    </div>
                  </el-tooltip>
                </div>
                <div v-else>
                  <el-tooltip placement="top-start" :content="scope.row[fruit] + ''">
                    <div class="one_line_hidden">
                      {{ scope.row[fruit] ? scope.row[fruit] : "-" }}
                    </div>
                  </el-tooltip>
                </div>
              </template>
            </el-table-column>
            <el-table-column align="center" fixed="right" width="200" prop="address" label="操作">
              <template slot-scope="scope">
                <el-button type="text" @click="Ramedetail(scope.row)">
                  详情
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col class="marginTop" style="text-align: right">
          <el-pagination :current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="count"
            layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
            @current-change="handleCurrentChange" />
        </el-col>
      </el-row>
    </div>
    <audit-record ref="refRecord" />
    <audit-detail ref="refDetail" :realname_details="realname_details" />
  </div>
</template>

<script>
  import {
    supplierLists,
  } from "@/api/supplier/index";
  import {
    supplierlist
  } from '@/api/supliersettent/index'
  import AuditRecord from './components/auditRecord.vue'
  import AuditDetail from './components/auditDetail.vue'
  const tableTheadOption = {
    supplier_name: {
      label: '供货商',
      field: 'supplier_name'
    },
    batch_number: {
      label: '结算批次号',
      field: 'batch_number'
    },
    start_time: {
      label: '结算范围',
      field: 'start_time'
    },
    total_price: {
      label: '结算金额',
      field: 'total_price'
    },
    delay_admin_name: {
      label: '结算人',
      field: 'delay_admin_name'
    },
    set_order_num: {
      label: '结算订单数',
      field: 'set_order_num'
    },
    remarks: {
      label: '结算备注',
      field: 'remarks'
    },
    created_at: {
      label: '结算时间',
      field: 'created_at'
    },
  }
  const allTableThead = ['supplier_name', 'batch_number', 'start_time', 'total_price','delay_admin_name','set_order_num','remarks','created_at'
  ]
  const defaultTableThead = ['supplier_name', 'batch_number', 'start_time', 'total_price','delay_admin_name','set_order_num','remarks','created_at'
  ]
  export default {
    components: {
      AuditRecord,
      AuditDetail
    },
    data() {
      return {
        options:[],//供应商列表
        searchFormtime:[],//搜索的结算时间
        realname_details:{},//实名详情
        kucunmer_id: {},
        // 动态显示表头默认表头
        tableTheadOptions: tableTheadOption,
        allTableThead: allTableThead,
        tableThead: defaultTableThead, // 默认表头
        checkboxTableThead: defaultTableThead, // 默认表头值
        tableKey: 1, // 为了保证table 每次都会重渲
        loading: false,
        GoodsLists: [],
        // 商品列表总条数
        total: 0,
        // 搜搜参数
        searchForm: {
          supplier_id: '',
          start_time: '',
          end_time:''
        },
        page: 1,
        count: 10,
      }
    },
    watch: {
      checkboxTableThead(valArr) {
        this.tableThead = this.allTableThead.filter(
          (i) => valArr.indexOf(i) >= 0
        )
        this.tableKey = this.tableKey + 1
      }
    },
    created() {
      this.getListWay()
      this.SupplierLists()
    },
    methods: {
      supliertime(e) {
        this.searchFormtime = e
        this.searchForm.start_time = e[0]
        this.searchForm.end_time = e[1]
      },
      //供应商列表
      SupplierLists() {
        supplierLists().then((res) => {
          this.options = res.data;
        });
      },
      //详情
      Ramedetail(row) {
        this.realname_details = row
        this.$refs.refDetail.open(row.id,row.supplier_id)
      },
      getQuery() {
        this.page = 1
        this.count = 10
        this.getListWay()
      },
      // 获取商品列表
      getListWay() {
        this.loading = true
        supplierlist({
            page: this.page,
            count: this.count,
            param:this.searchForm
          })
          .then((res) => {
            this.loading = false
            if (res.code !== 200 || res.status !== 1) {
              this.$messages.error(res.msg)
              return
            }
            this.GoodsLists = res.data.list
            this.total = res.data.total
          })
          .catch(() => {
            this.loading = false
          })
      },
      // 重置搜索条件
      resettingWay() {
        this.searchForm = {
          supplier_id: '',
          start_time:'',
          end_time:''
        }
        this.searchFormtime = []
        this.page = 1
        this.count = 10
        this.getListWay()
      },
      // 分页选择调用
      handleSizeChange(val) {
        this.count = val
        this.getListWay()
      },
      // 分页选择调用
      handleCurrentChange(val) {
        this.page = val
        this.getListWay()
      },
      //添加
      addGoodsWay() {
        this.$refs.refRecord.open()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .title {
    color: rgba(0, 0, 0, 0.85);
    font-weight: 500;
    font-size: 16px;
    line-height: 16px;
  }

  .sn {
    color: #606266;
    font-size: 13px;
  }

  .goodsaletr {
    border-radius: 5px;
    background-color: #f0faff;
    border: 1px solid #abdcff;
    color: #515a6e;
    font-size: 12px !important;
  }

  .demo-table-expand {
    display: flex;
    justify-content: start;
    flex-wrap: wrap;
    color: #515a6e;

    div {
      width: 30%;
      height: 40px;
      text-align: center;
      line-height: 40px;
      font-size: 12px;
    }
  }

  .marginTop {
    padding: 0 15px !important;
  }
</style>
<style>
  .el-upload--picture-card {
    width: 90px !important;
    height: 90px !important;
    line-height: 90px;
  }

  .el-upload-list--picture-card .el-upload-list__item-actions {
    width: 90px !important;
    height: 90px !important;
  }

  .el-upload-list--picture-card .el-upload-list__item-thumbnail {
    width: 90px !important;
    height: 90px !important;
  }

  .el-upload-list--picture-card .el-upload-list__item {
    width: 90px !important;
    height: 90px !important;
  }

  .tox .tox-dialog-wrap__backdrop {
    z-index: 9993 !important;
  }

  .tox-tinymce-aux {
    z-index: 9990 !important;
  }

  .tox .tox-dialog {
    z-index: 9995 !important;
  }
</style>
<style lang="scss" scoped>
  .phone {
    position: relative;
    margin-left: 50%;
    width: 380px;
    height: 800px;
    border: 5px solid #949494;
    border-radius: 40px;
    transform: scale(0.8) translateY(-50px);
  }

  .phone:before {
    content: "";
    position: absolute;
    width: 369px;
    height: 789px;
    // box-shadow: 0px 0px 24px #000;
    background-color: #000;
    border-radius: 33px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .phone:after {
    content: "";
    position: absolute;
    width: 364px;
    height: 786px;
    background: #fff;
    border-radius: 28px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .html {
    position: absolute;
    width: 364px - 5px - 5px;
    height: 786px - 5px - 5px;
    background: #fff;
    border-radius: 30px;
    overflow: hidden;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 5px;
    z-index: 1;
  }

  .receiver {
    position: absolute;
    top: 5px;
    left: 50%;
    margin-left: -50px;
    background: #000000;
    border: #484848 1px solid;
    width: 100px;
    height: 8px;
    z-index: 9;
    border-radius: 20px;
  }

  .receiver ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    margin: 1px;
    justify-content: space-around;
  }

  .receiver ul li {
    background: #303030;
    width: 1px;
    height: 1.5px;
    float: left;
    transform: skewX(-38deg);
  }

  .receiver div {
    width: 100px;
    height: 8px;
  }

  .receiver div:after {
    content: "";
    display: block;
    width: 95%;
    height: 83%;
    top: 1px;
    left: 3px;
    position: absolute;
    background-repeat: no-repeat;
    background-image: repeating-linear-gradient(to right,
        #434242,
        #000000 1px,
        rgba(255, 255, 255, 0) 1px,
        rgba(255, 255, 255, 0) 3px),
      repeating-linear-gradient(to right,
        #434242,
        #19191d 1px,
        rgba(255, 255, 255, 0) 1px,
        rgba(255, 255, 255, 0) 3px);
    background-size: 100% 50%;
    background-position: 0 0, 2px 4px;
    transform: skew(-25deg);
  }

  .labelView {
    width: 150px;
  }

  .infoDiv {
    display: flex;
    // align-items: center;
    background-color: #F5F5F5;
    border-radius: 6px;
    padding: 10px;
    margin-top: 10px;
    margin-bottom: 10px;

    .img {
      width: 65px;
      height: 65px;
      border-radius: 50%;
      background-color: #fff;
    }

    .right {}

    .scenter {
      flex: 1;
      margin-left: 10px;

      h3 {
        line-height: 30px;
        font-weight: 400;
        font-size: 16px;
        padding: 0px 0;
        margin: 0;
      }
    }
  }

  .orderdetail_item {
    display: flex;
    align-items: center;
    // width: 165px;
    justify-content: start;
    margin-right: 30px;

    p:nth-child(2) {
      color: #000;
      font-weight: 550;
      margin-left: 15px;
    }
  }

  .order_center {
    display: flex;
    align-items: center;
    justify-content: start;
    flex-wrap: wrap;
    padding: 0 2px 0 0;
    font-size: 13px;
    color: #666;
  }
</style>
